{extend name="public/base"/}
{block name="body"}
<style type="text/css">
	.attrs{margin-top:5px;}
	.attrname{width:100px;border:solid 1px #ddd;height:31px;font-size:14px;padding-left:4px;}
	.attrval{width:40%;border:solid 1px #ddd;height:31px;font-size:14px;padding-left:4px;}
	.layui-upload-file{display:none;}
</style>
<title>添加客栈</title>
</head>
<body>
<article class="page-container">
	<form class="form form-horizontal" id="form-admin-add">
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">房源：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<span class="select-box" style="width:150px;">
					<select class="select" name="h_id" size="1">
						{foreach $homestay as $key=>$value }
						<option value="{$value.id}">{$value.des}</option>
						{/foreach}
					</select>
				</span>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">可租日期：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input name="date" type="text" {literal} onfocus="WdatePicker()" {/literal} id="date" class="input-text Wdate" style="width:120px;" value="{$date}">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">当日价格：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="number" class="input-text" min="1" value="" placeholder="例：999" id="day_price" name="day_price" onkeyup="this.value= this.value.match(/\d+(\.\d{0,2})?/) ? this.value.match(/\d+(\.\d{0,2})?/)[0] : ''">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">是否已租：</label>
			<div class="formControls col-xs-8 col-sm-9">
               <label class="radio-inline">
                   <input disabled type="radio" id="is_rent1" name="is_rent" value="1" checked/>
                   <label for="more_bed1">未租</label>
               </label>
               <label class="radio-inline">
                   <input disabled type="radio" id="is_rent2" name="is_rent" value="2" />
                   <label for="more_bed2">已租</label>
               </label>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">是否启用：</label>
			<div class="formControls col-xs-8 col-sm-9">
               <label class="radio-inline">
                   <input type="radio" id="emailwy1" name="state" value="1" checked />
                   <label for="emailwy1">是</label>
               </label>
               <label class="radio-inline">
                   <input type="radio" id="emailwy2" name="state" value="2" />
                   <label for="emailwy2">否</label>
               </label>
			</div>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<input id="submit" class="btn btn-primary radius" type="button" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
			</div>
		</div>
	</form>
</article>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/static/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="/static/lib/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" src="/static/lib/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" src="/static/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script src="/static/lib/layui-v2.4.5/layui-v2.4.5/layui/layui.js"></script>
<script type="text/javascript">

	$(function(){
		$("#is_rent1").on('click',function(){
			$("#is_rent2").attr('checked', false);
			$(this).attr('checked', true);
		});
		$("#is_rent2").on('click',function(){
			$("#is_rent1").attr('checked', false);
			$(this).attr('checked', true);
		});
		$("#emailwy1").on('click',function(){
			$("#emailwy2").attr('checked', false);
			$(this).attr('checked', true);
		});
		$("#emailwy2").on('click',function(){
			$("#emailwy1").attr('checked', false);
			$(this).attr('checked', true);
		});
	});
	$("#submit").click(function() {
		var h_id=$("select[name=h_id]").val();
		var date=$("input[name=date]").val();
		var day_price=$("input[name=day_price]").val();
		var is_rent=$("input[name=is_rent][checked]").val();
		var state=$("input[name=state][checked]").val();
		$.ajax({
		    type: 'POST',
		    url: "{:url('homedate_add')}",
		    data: {h_id:h_id,date:date,day_price:day_price,is_rent:is_rent,state:state},
		    success: function(resdata){
		        if(resdata.code==200){
					layer.msg(resdata.msg,{icon:1,time:1000});
					setTimeout("parent.location.reload()",1000);
		        }else{
					layer.msg(resdata.msg,{icon:2,time:3000});
		        }
		    },
		    error: function(){
				layer.msg('数据保存失败',{icon:2,time:3000});
		    }
		})
	})
</script> 
{/block}